set
	I    suppliers /i1 * i20/   
	J    customers  /j1 * j25/  
	w    scenarios /w1 * w20/  
;

OPTIONS ITERLIM  = 100000, RESLIM   = 10000, LIMROW   = 10,
        LIMCOL   = 0,     SYSOUT   = OFF,   SOLPRINT = OFF,
        LP = cplex, NLP=MINOS5, MIP=cplex,  OPTCR = 0.0001,
	SEED = 1500;

* Write cplex options. We need to set options on the command line
* gams xxx.gms optfile=1

$onecho > cplex.opt 
heurfreq -1
cuts -1
preind 0
$offecho 

Parameters
	d(j, w)  demand at j in scenario w
	c(i, j)  cost to transport from i to j
	cap(i)   capacity at supplier i
	p(w)     probability of scenario w
*	bigm(w)
	bigm(j, w)
	bigm_cheat(j, w)
;

d(j, w) = normal(1, 0.2);
c(i, j) = uniform(0, 1);
*cap(i) = uniform(1, 2);
cap(i) = normal(2, 0.5);
p(w) = 1 / card(w);
*bigm(w) = 100;
*bigm(w) = smax(j, d(j,w));
bigm(j,w) = d(j, w);

Scalars
	alpha;
alpha = 0.7;

Variables
	x(i, j)
	y(w)
	z
;
Binary variable y;
Positive variable x;

Equations
	cost
	knapsack
	capacity(i)          for each supplier and all scenario
	chance_demand(j, w)  for each custormer and scenario
	chance_demand_cheat(j,w)
;
cost..                   z =e= sum( (i,j), x(i,j) * c(i,j) );
knapsack..           alpha =l= sum( w, p(w) * y(w) );
capacity(i)..       cap(i) =g= sum( j, x(i,j) );
chance_demand(j, w)..   sum(i, x(i,j)) - d(j, w)
			=g= bigm(j, w) * (y(w) - 1);
chance_demand_cheat(j,w).. sum(i, x(i,j)) - d(j, w)
			=g= bigm_cheat(j, w) * (y(w) - 1);

* Create the model
Model stoch_trnsport /cost, knapsack, capacity, chance_demand/;
Model stoch_trnsport_cheat /cost, knapsack, capacity, chance_demand_cheat/;

* Solve and cheat
Solve stoch_trnsport using mip minimizing z;
display x.L, y.L;
bigm_cheat(j, w) = abs(sum(i, x.L(i,j)) - d(j, w));
Solve stoch_trnsport_cheat using mip minimizing z;
display x.L, y.L;
display bigm, bigm_cheat;

	
	
	